package com.zeyi.chat.utils;

import com.zeyi.chat.controller.WindowMove;
import com.zeyi.chat.manager.StageManager;
import com.zeyi.chat.views.CircleBorder;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.io.IOException;

/**
 * @author zeyi
 */
public class FXMLUtil {

    private static Parent getParent(String path) {
        Parent root = null;
        try {
            root = FXMLLoader.load(FXMLUtil.class.getResource(path));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return root;
    }

    public static Scene createScene(String path) {
        Parent root = getParent(path);
        return new Scene(root);
    }

    public static Parent createRoot(String path) {
        return getParent(path);
    }

    public static Stage createStage(String path) {
        Scene scene = createScene(path);
        Stage stage = new Stage();
        stage.setScene(scene);
        new CircleBorder(scene, 5, "#DCDFE6");
        new WindowMove(stage, scene.getRoot());
        stage.initStyle(StageStyle.TRANSPARENT);
        stage.getIcons().add(new Image("/images/user.jpg"));
        stage.show();
        return stage;
    }
}
